﻿using System.Linq;
using System.Reflection;

namespace YioksPlanEditor.ObjectCopy
{
    public class Model : IModel
    {
        public string[] GetValues()
        {
            return null;
        }

        public string Descreption()
        {
            //反序列化操作 所定义的变量          
            PropertyInfo []
            oldpropertys = this.GetType().GetProperties(BindingFlags.Public | BindingFlags.SetProperty |
                                                   BindingFlags.Instance);
            string objStr = "";
            foreach (PropertyInfo info in oldpropertys)
            {
                object value = info.GetValue(this, null);
                objStr += info.Name + ":" + value + "\n";
            }
            return objStr;
        }

        public void SetDefaultProp(string propName, object defaultValue)
        {
            var oldpropertys = GetType().GetProperties(BindingFlags.Public | BindingFlags.SetProperty |
               BindingFlags.Instance);
            var info = oldpropertys.FirstOrDefault(t => t.Name.Equals(propName));
            if (info == null) return;
            if (info.GetValue(this, null) == null)
            {
                info.SetValue(this, defaultValue, null);
            }
        }
    }
}
